/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package smartgym.gui.tables;

import java.util.List;
import javax.swing.table.DefaultTableModel;
import smartgym.models.entities.Client;

/**
 *
 * @author Carlos
 */
public class ClientTableFrame extends TableFrameBase implements TableInterface{

    List<Client> clientList;

    /**
     * Creates new form ClientTableFrame
     */
    public ClientTableFrame() {
        super();
        //initComponents();
        this.setTableHeader(new String[]{"cpf", "nome", "vencimento", "status"});

        getObjectTable().setModel(new DefaultTableModel(new Object[0][0], getTableHeader()));
        getObjectTable().setVisible(true);


    }    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setLayout(new java.awt.BorderLayout());
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

    
    public void updateTable() {
        fillTable();
    }

    @Override
    public void fillTable() {
        Object[][] dados = new Object[clientList.size()][4];

        for (int i = 0; i < clientList.size(); i++) {
            Client client = (Client) clientList.get(i);
            dados[i][0] = client.getCpf();
            dados[i][1] = client.getName();
            dados[i][2] = client.getPaymentDay();
            if (client.isRegular()) {
                dados[i][3] = "Sim";
            } else {
                dados[i][3] = "Não";
            }

            getObjectTable().setModel(new DefaultTableModel(dados, this.getTableHeader()));

        }
    }
    
    @Override
    public void setObjectList(List objectList) {
        clientList = (List<Client>) objectList;
        updateTable();
    }

    @Override
    public Object getSelectRow() {
        int index;
        if((this.clientList == null )||(this.clientList.size()==0) ){
            return null;
        } else{
            index = this.getObjectTable().getSelectedRow();
            return this.clientList.get(index);
        }
        
    }
}
